{extend name="public/base"/}

{block name="title"}修改管理员密码{/block}
{block name="main"}
<div class="container-fluid">

    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-body">

                    <form method="post" action="" class="site-form">
                        <div class="form-group">
                            <label for="old-password">旧密码</label>
                            <input type="password" class="form-control" name="oldpwd" id="old-password"
                                   placeholder="输入账号的原登录密码">
                        </div>
                        <div class="form-group">
                            <label for="new-password">新密码</label>
                            <input type="password" class="form-control" name="newpwd" id="new-password"
                                   placeholder="输入新的密码">
                        </div>
                        <div class="form-group">
                            <label for="confirm-password">确认新密码</label>
                            <input type="password" class="form-control" name="confirmpwd" id="confirm-password"
                                   placeholder="确认密码">
                        </div>
                        <button type="submit" class="btn btn-primary" id="btn">修改密码</button>
                    </form>

                </div>
            </div>
        </div>

    </div>

</div>
{/block}
{block name="js"}
<script>
    $('#btn').click(function () {
        let op = $('#old-password').val();
        let np = $('#new-password').val();
        let cp = $('#confirm-password').val();
        if(np.length < 6){
            swal('密码最低6位', '', 'error');
            return false;
        }
        if(np != cp){
            swal('两次密码不一致', '', 'error');
            return false;
        }
        $.ajax({
            url: "/admin/user/password",
            data: {np: np, op: op},
            type: "POST",
            success: function (res) {
                if (res.code === 1) {
                    swal("修改成功,请重新登录...", {
                        buttons: false,
                        timer: 1500,
                        icon: 'success'
                    }).then(() => {
                        location.reload();
                    });
                } else {
                    swal(res.msg, '', 'error');
                }
            }
        });

    });
</script>
{/block}